home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / DTS Japan-Sample Code / AppleEvent•MacApp3.0b1•7.0 / UCore.h < prev    next >
Encoding:
Text File  |  1992-02-05  |  14.5 KB  |  487 lines  |  [TEXT/MPS ]

  1. // Copyright © 1991 Apple Computer, Inc. All rights reserved.
  2.  
  3. #ifndef    __UCORE__
  4. #define    __UCORE__
  5.  
  6. #ifndef    __MACAPP__
  7. #include <MacApp.h>
  8. #endif
  9.  
  10. #ifndef    __UDIALOG__
  11. #include <UDialog.h>
  12. #endif
  13.  
  14. #ifndef    __UBUSYCURSOR__
  15. #include <UBusyCursor.h>
  16. #endif
  17.  
  18. #ifndef    __UITERATOR__
  19. #include <UIterator.h>
  20. #endif
  21.  
  22. #ifndef    __TOOLUTILS__
  23. #include <ToolUtils.h>
  24. #endif
  25.  
  26. #ifndef    __RESOURCES__
  27. #include <Resources.h>
  28. #endif
  29.  
  30. #ifndef    __APPLEEVENTS__
  31. #include <AppleEvents.h>
  32. #endif
  33.  
  34. #ifndef    __EPPC__
  35. #include <EPPC.h>
  36. #endif
  37.  
  38. #ifndef    __GESTALTEQU__
  39. #include    <GestaltEqu.h>
  40. #endif
  41.  
  42. #ifndef    __SCRIPT__
  43. #include    <Script.h>
  44. #endif
  45.  
  46. #ifndef    __STRING__
  47. #include    <String.h>
  48. #endif
  49.  
  50. #ifndef    __DIALOGS__
  51. #include    <Dialogs.h>
  52. #endif
  53.  
  54. #ifndef    __PPCTOOLBOX__
  55. #include    <PPCToolbox.h>
  56. #endif
  57.  
  58. #ifndef __AEOBJECTS__
  59. #include <AEObjects.h>
  60. #endif
  61.  
  62. #ifndef __AEOBJECTPACKING__
  63. #include <AEPackObject.h>
  64. #endif
  65.  
  66. class TCell;            // forward declarations
  67. class TRecordCell;
  68.  
  69. typedef pascal void (*DoToACellProc)(TCell *aCell, void *params);
  70. typedef pascal Boolean (*TestACellProc)(TCell *aCell, void *params);
  71. typedef pascal void    (*DoToObject)(TObject *anObject, void *link);
  72. typedef pascal Boolean    (*TestItem)(TObject *anObject, void *link);
  73.  
  74. typedef TCell    *CellPtr;
  75. typedef enum CellState
  76. {    
  77.     kBlack,
  78.     kWhite,
  79.     kEmpty,
  80.     kNeighbor,
  81.     kAvailable
  82. } CellState;
  83.  
  84. typedef enum GameState
  85. {    
  86.     kWhiteTurn,
  87.     kBlackTurn,
  88.     kWhiteTurnPass,
  89.     kBlackTurnPass,
  90.     kGameOver
  91. } GameState;
  92.  
  93. typedef enum TestState
  94. {
  95.     kAnother,
  96.     kSame,
  97.     kNoHit,
  98.     kHit
  99. } TestState;
  100.     
  101. typedef enum Direction
  102. {
  103.     kNorth,
  104.     kNorthEast,
  105.     kEast,
  106.     kSouthEast,
  107.     kSouth,
  108.     kSouthWest,
  109.     kWest,
  110.     kNorthWest
  111. } Direction;
  112.  
  113. typedef enum InvertFlag
  114. {
  115.     kTest,
  116.     kInvert
  117. } InvertFlag;
  118.     
  119. typedef enum GameResult
  120. {    
  121.     kWin,
  122.     kDraw,
  123.     kLose,
  124.     kClose
  125. } GameResult;
  126.  
  127. typedef enum PlayerStatus
  128. {    
  129.     kFailed = -1,
  130.     kNotReady,
  131.     kReady
  132. } PlayerStatus;
  133.  
  134. typedef enum
  135. {    
  136.     kBeginTransactionReturnID = 'BT',
  137.     kNewElementReturnID = 'NE',
  138.     kSetDataReturnID = 'SD',
  139.     kEndTransactionReturnID = 'ET'
  140. } ReturnID;
  141.  
  142. const    OSType    kFileType            =    'TARO';
  143. const    OSType    kSignature            =    'TARO';
  144. const    OSType    kServerSignature    =    'Taro';
  145. const    OSType    kApplicationFType    =    'APPL';
  146.  
  147. const    AEEventClass    kTaroClass        =    'TARO';
  148. const    AEEventID    kGameOverID            =    'OVER';
  149. const    AEKeyword    keyGameResult        =    'RSLT';
  150. const    AEKeyword    keyClientName        =    'NAME';
  151.  
  152. const    DescType    typeTObjectPtr    =    typeMagnitude;
  153.  
  154. const    AEEventClass    kAECoreSuite    =    'core';
  155. const    DescType    cTable                =    'ctbl';
  156. const    DescType    cCell                =    'ccel';
  157. const    DescType    typeCell            =    'cell';
  158. const    AEEventID    kAENewElement        =    'nobj';
  159. const    AEEventID    kAESetData            =    'setd';
  160. const    AEEventID    kAEBeginTransaction    =    'begi';
  161. const    AEEventID    kAEEndTransaction    =    'endt';
  162. const    AEEventID    kAEAbout            =    'abou';
  163. const    AEKeyword    keyAEObjectClass    =    'kocl';
  164. const    AEKeyword    keyAEInsertHere        =    'insh';
  165. const    AEKeyword    keyAEData            =    'data';
  166. const    AEKeyword    keyAETheData        =    'kdat';
  167. const    AEKeyword    keyAETheTransID        =    'tran';
  168.  
  169. const    AEKeyword    keyTaroColumnNumber        =    'CNUM';
  170. const    AEKeyword    keyTaroRowNumber        =    'RNUM';
  171. const    AEKeyword    keyTaroColor            =    'COLR';
  172. const    AEKeyword    keyTaroUserName            =    'NAME';
  173. const    AEKeyword    keyTaroTableSpecifier    =    'TSPC';
  174.  
  175. const    OSErr    errAEFail                =    -1732;
  176. const    OSErr    errAEUserCanceled        =    -1740;
  177.  
  178. const    short    kPlayerString        =    2000;
  179. const    short    kStatusMessage        =    2001;
  180. const    short    kGameOverMessage    =    2002;
  181.  
  182. const    CommandNumber    cNewClient    =    cNew;
  183. const    CommandNumber    cNewServer    =    cNewClient + 1;
  184. const    CommandNumber    cNewElement    =    cNewServer + 1;
  185.  
  186. class    TPlayer;
  187. // ============================== Service Routines =================================
  188. char    TranslateCellSize(char    anItem);
  189. OSErr    CheckPPC(void);
  190. void    ShowModalDialog(short DialogID);
  191. void    InstallNotification(void);
  192.  
  193. class    TCoreDocument;
  194. class    TAppleEventPlayer;
  195. class    TNewServerCommand;
  196. class    TNewElementCommand;
  197. // ==========================================================================================
  198. class TCoreApplication: public TApplication {
  199. private:
  200.     TList    *    fNewElementCommandList;
  201. public:
  202.     virtual pascal void ITaroApplication(void);
  203.     virtual pascal void InsertNewElementCommand(TNewElementCommand * aNewElementCommand);
  204.     virtual pascal void RemoveNewElementCommand(void);
  205.     virtual pascal TNewElementCommand * GetNewElementCommand(void);
  206.  
  207.     virtual pascal TDocument * FindDocumentFromName(Str255 & theName);
  208.     virtual pascal TAppleEventPlayer * CreateServerPlayer(void);
  209. };
  210.  
  211. // ==========================================================================================
  212. class TCoreDocument: public TDocument {
  213. private:
  214.     char        fHCellSize;
  215.     char        fVCellSize;
  216.     TPlayer    *    fBlackPlayer;
  217.     TPlayer    *    fWhitePlayer;
  218.     GameState    fTurn;
  219. public:
  220.     virtual pascal void ICoreDocument(char aHCellSize, char aVCellSize, 
  221.                                     char aBlackPlayer, char aWhitePlayer);
  222.     virtual pascal TPlayer * CreatePlayer(char PlayerType, CellState aColor);
  223.     virtual pascal void DoMakeViews(Boolean forPrinting);
  224.     virtual pascal void SetPlayerStatus(void);
  225.     virtual pascal void GetCellSize(char & HCellSize, char & VCellSize);
  226.     virtual pascal void GameOver(void);
  227.     virtual pascal void GameClose(void);
  228.     virtual pascal void Free(void);
  229.     virtual pascal TPlayer * GetPlayer(GameState aState);
  230.     virtual pascal void Close(void);
  231.     virtual pascal GameState GetTurn(void);
  232.     virtual pascal CellState GetTurnCellState(void);
  233.     virtual pascal void SwitchTurn(Boolean Pass);
  234.     virtual pascal TPlayer * GetTemporaryPlayer(void);
  235.     virtual pascal TPlayer * GetAnotherPlayer(void);
  236.     virtual pascal void PlayerMove(TRecordCell * aMouseMove);
  237.     virtual pascal void SendTurn(void);
  238.     virtual pascal void CreateTableSpecifier(AEDesc & aTableSpec);
  239. };
  240.         
  241.  
  242. // ==========================================================================================
  243. class TScene: public TObject {
  244. private:
  245.     TList            *fCellList;
  246.     short    fBlack, fWhite;
  247.     short    fAvailable;
  248.     TCoreDocument    *fCoreDocument;
  249.     TList            *fNeighborCellList;
  250.     CellState    fTurn;
  251. public:
  252.     virtual pascal void IScene(TCoreDocument * aCoreDocument);
  253.     virtual pascal TCoreDocument * ReturnCoreDocument(void);
  254.     virtual pascal void AddCellLast(TCell *aCell);
  255.     virtual pascal TCell * GetCell(char aColumn, char aRow);
  256.     virtual pascal TCell * CreateCell(char aColumn, char aRow);
  257.     virtual pascal CellState GetTurn(void);
  258.     virtual pascal void SetTurn(CellState aTurn);
  259.     virtual pascal void GameOver(void);
  260.     virtual pascal void ChangeCount(CellState aColor, short aNumber);
  261.     virtual pascal short GetCount(CellState aColor);
  262.     virtual pascal void Free(void);
  263.     virtual pascal void SetInitialState(void);
  264.     virtual pascal void SearchAvailableCell(void);
  265.     virtual pascal void AddAvailable(void);
  266.     virtual pascal void ResetAvailable(void);
  267.     virtual pascal void AddNeighborCellLast(TCell *aCell);
  268.     virtual pascal short HasAvailableCell(void);
  269.     virtual pascal short GetAvailableCell(void);
  270.     virtual pascal TCell * SearchNeighborCellList(TRecordCell * theCoordinate);
  271.     virtual pascal void DeleteNeighborCell(TCell *theCell);
  272.     virtual pascal TList * GetNeighborCellList(void);
  273. };
  274.         
  275.         
  276. // ==========================================================================================
  277. class TCoordinate: public TObject {
  278. private:
  279.     char    fColumn, fRow;
  280. public:
  281.     virtual pascal void ICoordinate(const char column, const char row);
  282.     virtual pascal char GetColumn(void);
  283.     virtual pascal char GetRow(void);
  284.     virtual pascal Boolean IsEqual(TCoordinate *theCoordinate);
  285. };
  286.  
  287.  
  288. // ==========================================================================================
  289. class TRecordCell: public TCoordinate {
  290. private:
  291.     CellState    fState;
  292. public:
  293.     virtual pascal void IRecordCell(const char column, const char row, CellState aState);
  294.     virtual pascal CellState GetState(void);
  295.     virtual pascal GameState GetGameState(void);
  296.     virtual pascal void SetState(CellState aState);
  297.     virtual pascal Boolean IsEmpty(void);
  298.     virtual pascal Boolean IsNeighbor(void);
  299.     virtual pascal void SetNeighbor(void);
  300.     virtual pascal Boolean IsAvailable(void);
  301.     virtual pascal void SetAvailable(void);
  302.     virtual pascal TRecordCell * CloneRecordCell(void);    
  303. };
  304.  
  305.  
  306. // ==========================================================================================
  307. class TCell: public TRecordCell {
  308. private:
  309.     TScene    * fScene;
  310. public:
  311.     virtual pascal void ICell(TScene *aScene, const char column, const char row);
  312.     virtual pascal TScene * GetScene(void);
  313.     virtual pascal void ChangeState(void);
  314.     virtual pascal void PutPiece(void);
  315.     virtual pascal void SetNeighbor(void);
  316.     virtual pascal TCell * GetNeighborCell(Direction aDirection);
  317.     virtual pascal void SetNeighborCell(void);
  318.     virtual pascal TestState ScanOneDriection(    Direction aDirection,
  319.                                                             TestState aTestState,
  320.                                                             TCell * aCell);    
  321.     virtual pascal void GetCornerCoordinate(char & h, char & v,
  322.                                             char & aHCellSize, char & aVCellSize);
  323.     virtual pascal void ScanAllDriection(void);
  324.     virtual pascal void HitCell(TCell * aTurnCell);
  325. };
  326.  
  327.  
  328. // ==========================================================================================
  329. class TPlayer: public TObject {
  330. private:
  331.     TCoreDocument *    fCoreDocument;
  332.     Boolean            fPermission;
  333.     PlayerStatus    fStatus;
  334. public:
  335.     virtual pascal void Initialize(void);
  336.     virtual pascal void IPlayer(TCoreDocument * aCoreDocument);
  337.     virtual pascal void MyTurn(void);
  338.     virtual pascal void MyMove(TRecordCell * aCellRecord);
  339.     virtual pascal void YourMove(TRecordCell * aCellRecord);
  340.     virtual pascal pascal TCoreDocument * GetCoreDocument(void);
  341.     virtual pascal void SetCoreDocument(TCoreDocument * aCoreDocument);
  342.     virtual pascal Boolean GetPermission(void);
  343.     virtual pascal PlayerStatus GetStatus(void);
  344.     virtual pascal void SetStatus(PlayerStatus aStatus);
  345.     virtual pascal void GetName(Str255 & aString);
  346.     virtual pascal void MouseMove(TRecordCell * aMouseMove);
  347.     virtual pascal void GameOver(GameResult aResult);
  348. };
  349.  
  350.  
  351. class TTarget;
  352. // ==========================================================================================
  353. class TAppleEventPlayer: public TPlayer {
  354. private:
  355.     unsigned long    fTargetTransactionID;
  356.     CellState    fMyColor;
  357.     TTarget    *    fTarget;
  358.     TRecordCell * fMove;
  359.     Boolean        fWait;
  360.     AEDesc    fObjSpec;
  361. public:
  362.     virtual pascal void Initialize(void);
  363.     virtual pascal void IAppleEventPlayer(TCoreDocument * aCoreDocument, CellState aColor);
  364.     virtual pascal unsigned long GetTargetTransactionID(void);
  365.     virtual pascal void SetTargetTransactionID(unsigned long aTargetTransactionID);
  366.     virtual pascal void SetTargetTableSpecifier(AEDesc & TableSpec);
  367.     virtual pascal CellState GetMyColor(void);
  368.     virtual pascal void SetMyColor(CellState aColor);
  369.     virtual pascal void GameOver(GameResult aResult);
  370.     virtual pascal void MyTurn(void);
  371.     virtual pascal void MyMove(TRecordCell * aCellRecord);
  372.     virtual pascal void YourMove(TRecordCell * aCellRecord);
  373.     virtual pascal TTarget * ReturnTarget(void);
  374.     virtual pascal void SetTarget(TTarget * aTartget);
  375.     virtual pascal void EndTransaction(void);
  376.     virtual pascal void CreateTargetCellSpecifier(TRecordCell * aCell, AEDesc & dCellSpec);
  377.     virtual pascal void Free(void);
  378. };
  379.  
  380. // ==========================================================================================
  381. class TTarget: public TObject {
  382. private:
  383.     AEAddressDesc    fTargetAddress;
  384. public:
  385.     virtual pascal void ITarget(AEAddressDesc & TargetID);
  386.     virtual pascal void CreateDesc(DescType typeCode, Ptr dataPtr, Size dataSize);
  387.     virtual pascal void Free(void);
  388.     virtual pascal void SendSetData(TRecordCell * aMove, unsigned long    aTransactionID, AEDesc & cellSpec);
  389.     virtual pascal void SendEndTransaction(GameResult aResult, unsigned long theServer, TPlayer * theClient);
  390.     virtual pascal TAppleEvent * CreateAppleEvent(AEEventClass theAEEventClass, AEEventID theAEEventID,
  391.                                 short returnID, long transactionID);
  392.     virtual pascal void GetName(Str255 & userName);
  393. };
  394.  
  395. // ==========================================================================================
  396. class TServerTarget: public TTarget {
  397. private:
  398.     Str255    fUserName;
  399. public:
  400.     virtual pascal void IServerTarget(AEAddressDesc & TargetID);
  401.     virtual pascal void SetName(const Str255 & userName);
  402.     virtual pascal void GetName(Str255 & userName);
  403. };
  404.  
  405. // ==========================================================================================
  406. class TNoChangesCommand: public TCommand {
  407. private:
  408. public:
  409.     virtual pascal void INoChangesCommand(void);
  410. };
  411.  
  412. // ==========================================================================================
  413. class TCloseDocumentCommand: public TNoChangesCommand {
  414. private:
  415.     TCoreDocument    *    fDocument;
  416. public:
  417.     virtual pascal void ICloseDocumentCommand(TCoreDocument * aDocument);
  418.     virtual pascal void DoIt(void);
  419. };
  420.  
  421. // ==========================================================================================
  422. class TStartDocumentCommand: public TNoChangesCommand {
  423. private:
  424.     TCoreDocument    *    fDocument;
  425. public:
  426.     virtual pascal void IStartDocumentCommand(TCoreDocument * aDocument);
  427.     virtual pascal void DoIt(void);
  428. };
  429.  
  430. // ==========================================================================================
  431. class TNewElementCommand: public TServerCommand {
  432. private:
  433.     char    fServerHCellSize;
  434.     char    fServerVCellSize;
  435.     char    fServerColor;
  436.     TAppleEventPlayer * fNewServer;
  437. public:
  438.     virtual pascal void INewElementCommand(AppleEvent & theAppleEvent, AppleEvent & Reply);
  439.     virtual pascal void DoIt(void);
  440.     virtual pascal void HandleReply(AEDesc & aTargetObject);
  441.     virtual pascal void GetServerParameter(char & aHCellSize, char & aVCellSize, char & aColor,
  442.                     TAppleEventPlayer * (& aNewServer));
  443. };
  444.  
  445. // ==========================================================================================
  446. class TBeginTransactionCommand: public TServerCommand {
  447. private:
  448. public:
  449.     virtual pascal void IBeginTransactionCommand(AppleEvent & theAppleEvent, AppleEvent & Reply);
  450.     virtual pascal void DoIt(void);
  451. };
  452.  
  453. // ==========================================================================================
  454. class TEndTransactionCommand: public TServerCommand {
  455. private:
  456. public:
  457.     virtual pascal void IEndTransactionCommand(AppleEvent & theAppleEvent, AppleEvent & Reply);
  458. };
  459.  
  460. // ==========================================================================================
  461. class TSetDataCommand: public TServerCommand {
  462. private:
  463. public:
  464.     virtual pascal void ISetDataCommand(AppleEvent & theAppleEvent, AppleEvent & Reply);
  465.     virtual pascal void DoIt(void);
  466. };
  467.  
  468. // ==========================================================================================
  469. class TMoveCommand: public TCommand {
  470. private:
  471.     TPlayer        *    fPlayer;
  472.     TRecordCell    *    fMove;
  473. public:
  474.     virtual pascal void IMoveCommand(TPlayer * aPlayer, TRecordCell * aMove);
  475.     virtual pascal void DoIt(void);
  476. };
  477.  
  478. // ==========================================================================================
  479. class TSendTurnCommand: public TCommand {
  480. private:
  481. public:
  482.     virtual pascal void ISendTurnCommand(TCoreDocument * aCoreDocument);
  483.     virtual pascal void DoIt(void);
  484. };
  485.  
  486. #endif
  487.